﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using System.Web.Script.Serialization;

namespace Web.Controllers
{
    /// <summary>
    /// Json装箱控制器
    /// </summary>
    public abstract partial class JsonController : Controller
    {
        protected bool IsFileUpload;
        protected internal new JsonResult Json(object data)
        {
            if (IsFileUpload) return new JsonString(data, "text/html");
            return new JsonString(data);
        }

        protected override JsonResult Json(object data, string contentType, Encoding contentEncoding)
        {
            return Json(data, contentType, contentEncoding, new List<JavaScriptConverter>());
        }

        protected internal virtual JsonString Json(object data, string contentType, Encoding contentEncoding, IEnumerable<JavaScriptConverter> converters)
        {
            return new JsonString
            {
                Data = data,
                ContentType = contentType,
                ContentEncoding = contentEncoding,
                Converters = new List<JavaScriptConverter>(converters)
            };
        }
    }
}
